package com.itheima.test2;

import java.io.*;
import java.net.Socket;

public class KehuClient {
    public static void main(String[] args) throws IOException {
        //1.创建客户端对象
        Socket socket = new Socket("192.168.13.61",10086);
        //2.获取输出流
        OutputStream os = socket.getOutputStream();
        //字符->字节的桥梁
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os));
        //3.输出流写东西
        writer.write("你瞅啥");
        writer.newLine();
        writer.flush();
        //给一个结束标记
        socket.shutdownOutput();
        //获取输入流
        InputStream is = socket.getInputStream();
        //从流读数据
        //字节->字符的桥梁  InputStreamReader
        BufferedReader reader = new BufferedReader(new InputStreamReader(is));
        String s;
        while ((s=reader.readLine())!=null){
            System.out.println(s);
        }

        //4.释放资源
        socket.close();

    }

}
